--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

 --CALL uvse_ExistsOrCreate('ART_CATEG');

 DELETE FROM se_ART_CATEG;



-- select * from  uv_cfamilles



 INSERT INTO se_ART_CATEG
 (SELECT id categ_cod,
         codens ensemble_cod,
         0 enreg_id,
         regroup categregr_cod,
         'N' enreg_s,
         libelle categ_lib,
         NULL categ_lib2,
         NULL ordre_num,
         specif1 critlibre1_val,
         type critlibre2_val
    FROM uv_cfamilles) ;

 UPDATE se_ART_CATEG tf SET enreg_id=(select enreg_id FROM &erp.art_categ f WHERE f.categ_cod=tf.categ_cod) ;
 UPDATE se_ART_CATEG tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('categ_cod','ART_CATEG','O') ;

 commit;


select * from (
SELECT &outils.stragg(source) source,categ_cod, ensemble_cod, enreg_id, categregr_cod, enreg_s, categ_lib, categ_lib2, ordre_num, critlibre1_val, critlibre2_val
FROM (
  SELECT 'uv' source ,g.* FROM se_ART_CATEG g
  union all
  SELECT 'se' source ,g.* FROM &erp.ART_CATEG g
  )
GROUP BY  categ_cod, ensemble_cod, enreg_id, categregr_cod, enreg_s, categ_lib, categ_lib2, ordre_num, critlibre1_val, critlibre2_val
HAVING Count(1)!=2) r
ORDER BY categ_cod
